import type { PlasmoMessaging } from "@plasmohq/messaging"

import { useUIcontentStore } from "~store/uicontentStore"
import type { UIContentState } from "~type/UIcontent"

const handler: PlasmoMessaging.MessageHandler<
  UIContentState,
  UIContentState
> = async (req, res) => {
  const { getState, setState } = useUIcontentStore

  chrome.action.setBadgeTextColor({ color: "#ffffff" })
  chrome.action.setBadgeText({ text: req.body.showUI ? "open" : "close" })
  chrome.action.setBadgeBackgroundColor({
    color: req.body.showUI ? "#4dd1d6" : "#a39e9e"
  })
  setState(req.body)
  res.send(req.body)
}
export default handler
